/**
 * @author lk
 * @date 2022/6/7 21:55
 */
package com.mmall.thread;

import org.apache.commons.lang3.StringUtils;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

public class PathTest02 {
    public static void main(String[] args) {
        Path path = Paths.get("localhost", "abc", "sdf");
        for (int i = 0; i < 10; i++) {
            path = Paths.get("iii", "" + i);
//            path = Path.of("C:\\", "iii", "+");
//            path = Path.of("G:\\", "Project\\java\\spring_learning_0515\\05-learn-java\\src\\main\\java\\com\\mmall\\thread\\PathTest02.java");
            path = path.resolve("C\\asd\\");
            path = path.resolveSibling("asssd");
            path = path.toAbsolutePath();
            Path p = path.getParent();
            System.out.println("p = " + p);
            Path file = path.getFileName();
            System.out.println("file = " + file);
            Path root = path.getRoot();
            System.out.println("root = " + root);
            System.out.println(path);
        }
    }
}

class FilesTest02 {
    public static void main(String[] args) throws IOException {
//        Path path = Path.of("pom.xml");
//        byte[] bytes = Files.readAllBytes(path);
//        String s = new String(bytes, StandardCharsets.UTF_8);
////        System.out.println(s);
//        List<String> strings = Files.readAllLines(path);
//        strings.forEach(System.out::println);
        Predicate<Path> predicate = ((Predicate<Path>)
                Files::isRegularFile)
                .and(Files::isReadable)
                .and(p -> StringUtils.equalsAnyIgnoreCase(p.getFileName().toString(), "pom.xml", "skdj.lakdsj"));
        String rootPath = ".";
        Path root = Path.of(rootPath);
        Files.list(root)
                .filter(predicate)
                .forEach(FilesTest02::printIt);

    }

    static void printIt(Path path) {
        try {
            System.out.println(Files.readAllLines(path));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
